﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SitePagePopUp.Master" AutoEventWireup="true" CodeBehind="CategoryPriority.aspx.cs" Inherits="TranTekBE.CategoryPriority" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="BodyPopupContent" runat="server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <table style="width:100%">
                <input type="hidden" runat="server" id="hdCatPriority" />
                <tr>
                    <td colspan="2" class="msgError"><asp:Literal ID="ltError" runat="server" />&nbsp;</td>
                </tr>
                <tr>
                    <td style="width:80%" class="tdCenterM"><asp:ListBox ID="lbCategories" runat="server" Width="98%" Height="380px" DataTextField="catName" DataValueField="CategoryISN" SelectionMode="Single" /></td>
                    <td style="width:20%" class="tdCenterM">
                        <button type="button" id="btnUp" style="width:70px">Up</button><br />
                        <button type="button" id="btnDown" style="width:70px">Down</button>
<%--                        <asp:Button ID="btnUp" runat="server" Text="Up" Width="70px" onclientclick="return CheckSelectItem()" CommandName="MoveUp" oncommand="ControlClick_Command" />
                        <asp:Button ID="btnDown" runat="server" Text="Down" Width="70px" onclientclick="return CheckSelectItem()" CommandName="MoveDown" oncommand="ControlClick_Command" />--%>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" class="tdCenterM">
                        <asp:Button ID="btnSubmit" Text="Ok" runat="server" Width="70px" CommandName="Save" oncommand="ControlClick_Command" />
                        <button id="btnCancel" style="width:70px;" type="button">Cancel</button>
                    </td>
                </tr>
            </table>
            <script type="text/javascript">
                function LoadJS(){
                    $("#btnCancel").on("click", function() {
                        window.parent.CloseDialog();
                    });
                    $("#btnUp").on("click", function() {
                        if (CheckSelectItem() == true)
                            MoveUpOrDown(true);
                    });
                    $("#btnDown").on("click", function() {
                        if (CheckSelectItem() == true)
                            MoveUpOrDown(false);
                    });
                }
                function MoveUpOrDown(isUp) {
                    var $op = $("select[id*='lbCategories'] option:selected");
                    if ($op.length) {
                        (isUp == true) ? $op.first().prev().before($op) : $op.last().next().after($op);
                    }
                    GetCatPriority();                    
                }
                function GetCatPriority() {
                    var txt = $("select[id*='lbCategories'] option").map(function() { return this.value }).get().join(",");
                    $("input[id*='_hdCatPriority']").val(txt);
                }
                function CheckSelectItem() {
                    if ($("select[id*='lbCategories']").val() == null){
                        alert("Please select Category.");
                        return false;
                    }
                    return true;
                }
            </script>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>